@include('common.header')
<link rel="stylesheet" href="{{ asset('/css/list.css') }}">
<link rel="stylesheet" href="{{ asset('/css/style.css') }}">
<script type="text/javascript" >

	// 点击充值
	function chongzhi( user_id,phone )
	{
		// 标题
		$("#chongzhi").html("会员充值 : "+phone);
		// 属性
		$("#chongzhi").attr("user_id",user_id);
	}
	
	
	// 日志浏览
	function rizhi( user_id,phone )
	{
		// 标题
		$("#rizhi").html("会员充值记录 : "+phone);
		// 获取记录
		$.ajax({
			type:"post",
			url:"{{ url('/getLog') }}",
			data:{user_id:user_id,_token:_token},
			async:true,    					
			dataType:"html",
			success:function(back)
			{
				$("#rizhi-body").html('');
				$("#rizhi-body").append(back);
			}
		});
	}
	
</script>


<div class="row" style="width:100%;margin-top:5%;" >
	<div class="col-md-5" >
		<nav style="margin-right:-200px;">
			<ol class="cd-breadcrumb custom-separator custom-icons" style="width:230px;" >
				<li><a href="{{ url('/') }}">首页</a></li>
				<li class="current"><a href="{{ url('/user') }}">vip列表</a></li>
			</ol>
		</nav>
	</div>
	<div class="col-md-7" style="text-align:left;margin-top:20px;">
		<!-- 搜索框 -->
		<form action="{{ url('/user') }}" method='post'   >
			<div class="input-group" style="width:400px;"  >
				
				{{ csrf_field() }}
				<input  type="text" name='keyword' class="form-control" placeholder="输入手机号码 ...." value="{{ $request or '' }}" style="border-radius:10px 0px 0px 10px;" />
				
				<span class="input-group-btn">
					<input class="btn btn-success" type="submit" value="Go!" />
					<a class="btn btn-default" href="{{ url('/user') }}" style="border-radius:0px 10px 10px 0px;" />清空条件</a>
				</span>
				
			</div>
		</form>
	</div>
</div>


<!-- 用户表格 -->
<!-- class="bs-example" -->
<div  class="wrap" style="width:90%;margin-top:2%;" >
	<!-- class="table table-hover" -->
    <table class="listtab" >
		<thead>
			<tr>
				<th></th>
				<th>id</th>
				<th>手机号</th>
				<th>实际充值</th>
				<th>赠送充值</th>
				<th>账户余额</th>
				<th>充值</th>
				<th>充值日志</th>
			</tr>
		</thead>
		<tbody>
			@forelse($user as $user_info)
				<tr>
					<td></td>
					<td>{{ $user_info->id }}</td>
					<td>{{ $user_info->phone }}</td>
					<td>{{ $user_info->realMoney }}</td>
					<td>{{ $user_info->giftMoney }}</td>
					<td>{{ $user_info->money }}</td>
					<td>
						<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#chongzhiModal" data-whatever="@mdo" onclick="chongzhi({{ $user_info->id }},'{{ $user_info->phone }}');" >
							充值
						</button>
					</td>
					<td>
						<button type="button" onclick="rizhi({{ $user_info->id }},'{{ $user_info->phone }}');" class="btn btn-primary" data-toggle="modal" data-target="#rizhiModal">
							日志
						</button>
					</td>
				</tr>
			@empty
				<tr>
					<td scope="row"><h2>暂无数据</h2></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			@endforelse
		</tbody>
    </table>
</div>


<!-- 日志模态框 -->
<div class="modal fade" id="rizhiModal" tabindex="-1" role="dialog" aria-labelledby="rizhiModalLabel">
	<div class="modal-dialog" role="document" style="top:10%;" >
		<div class="modal-content">
			
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="rizhi" ></h4>
			</div>
			<div class="modal-body" id="rizhi-body" style="height:auto;display:block;" >
				
				<!-- class="popover fade right in" -->
				<!-- <div class="arrow" style="top: 50%;"></div> -->
				
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>


<!-- 充值模态框 -->
<div class="modal fade" id="chongzhiModal" tabindex="-1" role="dialog" aria-labelledby="chongzhiModalLabel" >
	<div class="modal-dialog" role="document" style="top:10%;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="chongzhi" user_id='' ></h4>
			</div>
			<div class="modal-body">
				<form>
				
					<!-- 充值金额 -->
					<div class="form-group">
						<label for="recipient-name" class="control-label">充值金额 :
							<!-- 快捷选择  -->
							<div class="btn-group" data-toggle="buttons">
								
								<label class="btn btn-info active" style="margin-left:20px;margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#realMoney').val('100');" >
									<input type="radio" name="options" id="option1" autocomplete="off" checked>
									100
								</label>
								
								<label class="btn btn-info" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#realMoney').val('200');"  >
									<input type="radio" name="options" id="option2" autocomplete="off">
									200
								</label>
								
								<label class="btn btn-warning" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#realMoney').val('300');"  >
									<input type="radio" name="options" id="option3" autocomplete="off">
									300
								</label>
								
								<label class="btn btn-warning" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#realMoney').val('500');"  >
									<input type="radio" name="options" id="option3" autocomplete="off">
									500
								</label>
								
								<label class="btn btn-danger" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#realMoney').val('800');"  >
									<input type="radio" name="options" id="option3" autocomplete="off">
									800
								</label>
								
							</div>
							
						</label>
						<input type="text" class="form-control" id="realMoney" value="" />
					</div>
					
					<!-- 赠送金额 -->
					<div class="form-group">
						
						<label for="message-text" class="control-label">赠送金额 :
						
							<!-- 快捷选择  -->
							<div class="btn-group" data-toggle="buttons">
								
								<label class="btn btn-info active" style="margin-left:20px;margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#giftMoney').val('10');" >
									<input type="radio" name="options" id="option1" autocomplete="off" checked>
									10
								</label>
								
								<label class="btn btn-info" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#giftMoney').val('20');"  >
									<input type="radio" name="options" id="option2" autocomplete="off">
									20
								</label>
								
								<label class="btn btn-warning" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#giftMoney').val('30');"  >
									<input type="radio" name="options" id="option3" autocomplete="off">
									30
								</label>
								
								<label class="btn btn-warning" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#giftMoney').val('50');"  >
									<input type="radio" name="options" id="option3" autocomplete="off">
									50
								</label>
								
								<label class="btn btn-danger" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#giftMoney').val('100');"  >
									<input type="radio" name="options" id="option3" autocomplete="off">
									100
								</label>
								
							</div>
						
						</label>
						<input type="text" class="form-control" id="giftMoney">
						<!--<textarea class="form-control" id="message-text"></textarea>-->
					</div>
					<div class="motai" style="width:260px;height:40px;background:red;display:none;position:fixed;top:4%;left:43%;z-index:1000;text-align:center;color:#fff;font-size:17px;line-height:42px;border-radius:10px 10px 10px 10px;" ></div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" id="chong" >充值</button>
			</div>
		</div>
	</div>
</div>


<!-- 分页 -->
<div style='text-align:center;'>
	{{ $user->appends(['keyword'=>$request])->links() }}
</div>
<div class="badge" style="width:100%;text-align:center;font-size:18px;margin-bottom:70px;" >
		共{{ $user->total() }}条数据
</div>


<script>
	
	$(function()
	{
		// 充值
		$("#chong").click(function()
		{
			// 会员id
			var user_id = $("#chongzhi").attr("user_id");
			// 正则 为整数 1到5位
			var reg = /^[\d]{1,5}$/;
			// 充值 金额
			var realMoney = $("#realMoney").val();
			if( !reg.test(realMoney) || realMoney== '' || realMoney <= '0' )
			{
				$(".motai").html('请重新输入充值金额');
				$(".motai").slideDown(1000);
				$(".motai").delay(1500).slideUp(1000);
				return false;
			}
			// 赠送金额
			var giftMoney = $("#giftMoney").val();
			// 赠送金额 可以为空
			if( giftMoney!='' )
			{
				if( !reg.test(giftMoney) || giftMoney <= '0' || giftMoney>=(Math.ceil(realMoney/8))  )
				{
					$(".motai").html('请重新输入赠送金额');
					$(".motai").slideDown(1000);
					$(".motai").delay(1500).slideUp(1000);
					return false;
				}
			}
			$.ajax({
				type:"post",
				url:"{{ url('/moneyAdd') }}",
				data:{realMoney:realMoney,giftMoney:giftMoney,user_id:user_id,_token:_token},
				async:true,    					
				dataType:"json",
				success:function(back)
				{
					if( back['show_info'].indexOf("成功") > 0 )
					{
						$(".motai").html(back['show_info']);
						$(".motai").slideDown(1000);
						$(".motai").delay(2000).slideUp(1000);
						setTimeout(function(){
							window.location.href="{{ url('/user') }}";
						},2500);
					}else
					{
						$(".motai").html(back['show_info']);
						$(".motai").slideDown(1000);
						$(".motai").delay(1500).slideUp(1000);
					}
				}
			});
		});
		
	});
	
</script>


@extends('common.footer')

